// pages/person/person.js
import {
  get_carte,
  get_carte_count,
  get_open_id,
  user_login,
  baseUrl
} from "../../utils/api.js";

const app = getApp()

Page({

  /**
   * 页面的初始数据
   */
  data: {
    bossId: '',
    companyId: '',
    u_id: "",
    v_id: "",
    codeShow: false,
    companyShow: false,
    telShow: false,
    userinfoShow: false,
    code_btn: '关闭',
    code: '',
    tel: '',
    tel_: '',
    code_: '',
    inviteId: '',
    countList: [{
        name: '待付款',
        icon: '../../images/person/wallet.png',
        content: 80,
        statusNum: '0'
      },
      {
        name: '待发货',
        icon: '../../images/person/wait.png',
        content: 10,
        statusNum: '0'
      },
      {
        name: '待收货',
        icon: '../../images/person/logisitics.png',
        content: 8,
        statusNum: '0'
      },
      {
        name: '退换/售后',
        icon: '../../images/person/turn.png',
        content: 4,
        statusNum: '0'
      }
    ],
    TaskShow: 0,
    is_sale: '',
    codePlace: '获取验证码',
    setInter: '',
    authSettingUser_task: true,
    hehuoShow: 0,
    scollTop: 0,
  },
  to_login: function() {
    this.setData({
      authSettingUser_task: true,
    });
    wx.navigateTo({
      url: '/shopPages/login/login',
    })
  },
  hiden_task: function() {

    this.setData({
      authSettingUser_task: true,
    });
  },
  bindjifen: function() {
    if (app.globalData.authSettingUser > 0) {
      wx.navigateTo({
        url: '../../shopPages/integral/integral',
      })
    } else {
      this.setData({
        authSettingUser_task: false
      });
    }

  },
  sync_integral: function() {
    if (app.globalData.authSettingUser > 0) {
      wx.showModal({
        title: '提示',
        content: '是否同步积分',
        showCancel: false,
        success: function() {
          var that = this;
          var url2 = '/user_api/sync_integral';
          var params2 = {
            uid: app.globalData.userInfo.id,
            timestamp: new Date().getTime(),
          };
          params2.sign = app.getSign(params2)
          app.HttpPostSend(url2, params2, function(res) {
            wx.showModal({
              title: '提示',
              content: res.msg,
              showCancel: false,
              success: function() {

              }
            })

            // fn(res)
          });
        }
      })
    } else {
      this.setData({
        authSettingUser_task: false
      });
    }


  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    // this.getCarteCount(options.u_id)
    if (options.share_id && options.carte_id) {
      app.globalData.shareOptions = {
        share_id: options.share_id,
        carte_id: options.carte_id,
      }
      that.setData({
        u_id: options.share_id
      })
      app.globalData.SwitchTabParams.v_id = options.carte_id;
    } else {

      app.globalData.shareOptions.carte_id = app.globalData.SwitchTabParams.v_id
    }
    wx.getSystemInfo({
      success: res => {
        //导航高度
        this.setData({
          statusBarHeight: res.statusBarHeight + 44
        })
      },
      fail(err) {
        console.log(err);
      }
    })
  },
  chooseimage: function() {
    var that = this;
    if (that.data.u_id == that.data.v_id) {
      wx.chooseImage({
        count: 1, // 默认9
        sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
        sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
        success: function(res) {
          var url = '/dynamics_api/dynaUploadsImg';
          wx.uploadFile({
            url: baseUrl + url, // 仅为示例，非真实的接口地址
            filePath: res.tempFilePaths[0],
            name: 'file',
            formData: {},
            success(resp) {
              let json_res = JSON.parse(resp.data)
              if (json_res.msg != "success") {
                app.showTipMsg(json_res.msg);
              } else {
                that.getUserPic(json_res.data);
              }
            },
            fail(err) {
              console.log(err)
            }
          })

        }
      })
    }
  },

  // 检测是否需要登录
  checkUserInfo: function() {
    const that = this
    let openid = wx.getStorageSync('openid')
    if (openid) {
      app.globalData.openid = openid
      that.setData({
        openid,
      })
      let url = '/user_api/getInfoByOpenID';
      app.HttpPostSend(
        url, {
          openid: openid,
        },
        function(result_data) {
          if (result_data.msg != "success") {
            app.showTipMsg(result_data.msg);
          } else {
            if (!!result_data.data) { //如果后台有数据
              app.globalData.userInfo = {
                ...result_data.data
              }
              wx.setStorage({
                key: 'userInfo',
                data: JSON.stringify({
                  ...result_data.data
                })
              })
              that.setData({
                haveTap: 1,
                userInfo: result_data.data,
                is_sale: app.globalData.userInfo.is_sale
              })

              if (app.globalData.userInfo) {
                that.setData({
                  u_id: app.globalData.userInfo.id,
                  userInfo: app.globalData.userInfo,
                })
                app.update_cart(app.globalData.userInfo.id);
              }
              // app.globalData.SwitchTabParams.v_id = result_data.data.id
              that.getCarteInfo(result_data.data.id);
              that.companyInvite();
              var url2 = '/order/OrderCountByStatus';
              var params2 = {
                uid: app.globalData.userInfo.id
              };
              app.HttpPostSend(url2, params2, function(res) {
                if (res.msg != "success") {
                  app.showTipMsg(res.msg);
                } else {
                  var countList = that.data.countList;
                  if (res.data) {
                    countList[0].statusNum = res.data.obligations;
                    countList[1].statusNum = res.data.delivery;
                    countList[2].statusNum = res.data.receive;
                    countList[3].statusNum = res.data.after;
                  }
                  that.setData({
                    countList: countList
                  })
                }
              });

            } else { //如果后台无数据
              wx.login({
                success(res) {
                  let params = {
                    code: res.code
                  }
                  app.HttpGetSend(get_open_id, params, function(result) {
                    if (result.msg != "success") {
                      app.showTipMsg(result.msg);
                    } else {
                      app.globalData.openid = result.data.openid.openid;
                      // app.update_cart(result.data.userinfo.id);
                      wx.setStorage({
                        key: 'openid',
                        data: result.data.openid.openid
                      })
                      that.setData({
                        openid: result.data.openid.openid
                      })
                      that.setData({
                        TaskShow: 1,
                        openid: result.data.openid.openid
                      })
                    }
                  })
                }
              })
            }
          }
        })
    } else {
      wx.login({
        success(res) {
          let params = {
            code: res.code
          }
          app.HttpGetSend(get_open_id, params, function(result) {
            if (result.msg != "success") {
              app.showTipMsg(result.msg);
            } else {
              // app.update_cart(result.data.userinfo.id);
              app.globalData.openid = result.data.openid.openid;
              wx.setStorage({
                key: 'openid',
                data: result.data.openid.openid
              })
              wx.setStorage({
                key: 'userInfo',
                data: JSON.stringify(result.data.userinfo)
              })

              that.setData({
                TaskShow: 1,
                openid: result.data.openid.openid,
                userInfo: result.data.userinfo
              })
            }
          })
        }
      })
    }

    let systemInfo = wx.getSystemInfoSync()
    app.globalData.systemInfo = systemInfo
    this.setData({
      systemInfo
    })
  },

  // 获取用户信息
  bindGetUserInfo: function(e) {
    const that = this
    let userInfo = e.detail.userInfo
    try {
      app.HttpPostSend(
        user_login, {
          openid: that.data.openid,
          username: userInfo.nickName,
          logo: userInfo.avatarUrl,
          sex: userInfo.gender
        },
        function(result_data) {
          if (result_data.msg != "success") {
            app.showTipMsg(result_data.msg);
          } else {
            let userInfo = {
              ...result_data.data
            }
            app.globalData.userInfo = userInfo
            wx.setStorage({
              key: 'userInfo',
              data: JSON.stringify(userInfo)
            })
            that.setData({
              TaskShow: 0,
              haveTap: 1,
              userInfo: userInfo,
              is_sale: userInfo.is_sale
            })

            if (app.globalData.userInfo) {
              that.setData({
                u_id: app.globalData.userInfo.id,
                userInfo: app.globalData.userInfo,
              })
            }
            // app.globalData.SwitchTabParams.v_id = userInfo.id
            that.getCarteInfo(userInfo.id);
            var url2 = '/order/OrderCountByStatus';
            var params2 = {
              uid: app.globalData.userInfo.id
            };
            app.HttpPostSend(url2, params2, function(res) {

              if (res.msg != "success") {
                app.showTipMsg(res.msg);
              } else {
                var countList = that.data.countList;
                if (res.data) {
                  countList[0].statusNum = res.data.obligations;
                  countList[1].statusNum = res.data.delivery;
                  countList[2].statusNum = res.data.receive;
                }
                that.setData({
                  countList: countList
                })
              }
            });
          }
        })
    } catch (error) {

    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    const that = this
    this.checkUserInfo()
    that.setData({
      show_onlogin: app.globalData.authSettingUser
    });

  },
  show_login: function() {
    console.log(1);
    this.setData({
      authSettingUser_task: false
    });
  },
  gz_template: function() {

    var that = this;
    if (app.globalData.authSettingUser > 0) {
      wx.login({
        success: function(r) {
          var code = r.code; //登录凭证
          if (code) {

            that.getSessionKey(code);

          } else {
            console.log('获取用户登录态失败！' + r.errMsg)
          }

        },
        fail: function() {

        }
      })
    } else {
      that.setData({
        authSettingUser_task: false
      });
    }


  },
  getSessionKey: function(code, fn) {
    var that = this;
    var url2 = '/user_api/get_session_key';
    var params2 = {
      code: code
    };
    app.HttpPostSend(url2, params2, function(res) {
      console.log("+++++++++++++++++" + res.data);
      wx.showModal({
        title: '提示',
        content: res.msg,
        showCancel: false,
        success: function() {

        }
      })

      // fn(res)
    });
  },


  // 获取名片信息
  getCarteInfo: function(u_id) {

    const that = this
    // const v_id = app.globalData.SwitchTabParams.v_id
    // if (v_id>0){

    // }else{
    //   v_id = u_id
    // }
    if (app.globalData.CarteInfo) {

      that.setData({
        CarteInfo: app.globalData.CarteInfo,
      })
    } else {

      try {
        // 获取名片信息
        app.HttpGetSend(get_carte, {
            uid: u_id,
            v_id: u_id
          },
          function(res) {
            if (res.msg != "success") {
              // app.showTipMsg(res.msg);
              if (res.code == -100) {
                that.setData({
                  userinfoShow: true
                });
              } else {
                wx.showModal({
                  title: '提示',
                  content: res.msg,
                  showCancel: false,
                  success: function() {}
                })
              }

              return false;
            } else {
              let checkNullEmpty = (aim) => {
                if (aim != '' && aim != null) {
                  return true
                } else {
                  return false
                }
              }
              // 名片信息
              let CarteInfo = new Object()
              CarteInfo.id = res.data.id
              CarteInfo.is_allow = res.data.is_allow
              // 名片 形象照
              CarteInfo.img = new Object()
              CarteInfo.img = {
                type: 0,
                src: '../../images/img_block.png'
              }
              if (checkNullEmpty(res.data.img)) {
                CarteInfo.img = {
                  type: 1,
                  src: res.data.img
                }
              }
              // 名片 公司名
              CarteInfo.comName = new Object()
              CarteInfo.comName = {
                type: 0,
                content: '公司'
              }
              if (checkNullEmpty(res.data.company)) {
                CarteInfo.comName = {
                  type: 1,
                  content: res.data.company
                }
              }
              // 名片 公司logo
              CarteInfo.comLogo = new Object()
              CarteInfo.comLogo = {
                type: 0,
                src: '../../images/carteFavorites/logo_block.png'
              }
              if (checkNullEmpty(res.data.com_logo)) {
                CarteInfo.comLogo = {
                  type: 1,
                  src: res.data.com_logo
                }
              }
              // 名片 职业
              CarteInfo.position = new Object()
              CarteInfo.position = {
                type: 0,
                content: '职业'
              }
              if (checkNullEmpty(res.data.position)) {
                CarteInfo.position = {
                  type: 1,
                  content: res.data.position
                }
              }
              // 名片 名字
              CarteInfo.name = new Object()
              CarteInfo.name = {
                type: 0,
                content: '名字'
              }
              if (checkNullEmpty(res.data.name)) {
                CarteInfo.name = {
                  type: 1,
                  content: res.data.name
                }
              }
              // 名片 手机号
              CarteInfo.mobile = new Object()
              CarteInfo.mobile = {
                type: 0,
                content: '手机号'
              }
              if (checkNullEmpty(res.data.mobile)) {
                CarteInfo.mobile = {
                  type: 1,
                  content: res.data.mobile
                }
              }
              // 名片 邮箱
              CarteInfo.email = new Object()
              CarteInfo.email = {
                type: 0,
                content: '邮箱'
              }
              if (checkNullEmpty(res.data.email)) {
                CarteInfo.email = {
                  type: 1,
                  content: res.data.email
                }
              }
              // 名片 地址
              CarteInfo.address = new Object()
              CarteInfo.address = {
                type: 0,
                content: '地址'
              }
              if (checkNullEmpty(res.data.address)) {
                CarteInfo.address = {
                  type: 1,
                  content: res.data.address
                }
              }
              that.setData({
                CarteInfo
              })
              app.globalData.CarteInfo = CarteInfo
            }
          })
      } catch (err) {
        console.log(err)
      }
    }
  },
  showAddvideo: function() {
    if (app.globalData.authSettingUser > 0) {
      wx.navigateTo({
        url: '../../shopPages/videoCourse/videoCourse',
      })
    } else {
      this.setData({
        authSettingUser_task: false
      });
    }

  },
  //联系客服
  showAddKf: function() {
    if (app.globalData.authSettingUser > 0) {
      wx.navigateTo({
        url: '../socks/socks?mid=191'
      })
    } else {
      this.setData({
        authSettingUser_task: false
      });
    }

  },
  //点击地址管理
  showAddress: function(e) {
    if (app.globalData.authSettingUser > 0) {
      var that = this;
      var url2 = '/address/index';
      var params2 = {
        uid: app.globalData.userInfo.id
      };
      app.HttpGetSend(url2, params2, function(res) {
        if (res.msg != "success") {
          app.showTipMsg(res.msg);
        } else {

          wx.navigateTo({
            url: '/pages/myAddress/myAddress?gotype=person',
          })
        }
      });
    } else {
      this.setData({
        authSettingUser_task: false
      });
    }

  },
  //点击进入销售排行
  showSalesRank: function(e) {
    if (app.globalData.authSettingUser > 0) {
      wx.navigateTo({
        url: '/pages/salesRank/salesRank',
      })
    } else {
      this.setData({
        authSettingUser_task: false
      });
    }

  },
  // 获取个人名片数据统计
  getCarteCount: function(id) {
    const that = this
    app.HttpGetSend(
      get_carte_count, {
        uid: id
      },
      function(res) {
        if (res.msg != "success") {
          app.showTipMsg(res.msg);
        } else {

        }
      })
  },

  // 打开名片夹 页面
  showCarteList: function() {

    if (app.globalData.authSettingUser > 0) {
      wx.navigateTo({
        url: '/pages/carteFavorites/carteFavorites'
      })
    } else {
      this.setData({
        authSettingUser_task: false
      });
    }

  },

  // 打开我的钱包 页面
  showMyMoney: function() {
    if (app.globalData.authSettingUser > 0) {
      wx.navigateTo({
        url: '/pages/myMoney/myMoney'
      })
    } else {
      this.setData({
        authSettingUser_task: false
      });
    }

  },

  // 打开我的订单 页面
  showMyOrders: function() {

    if (app.globalData.authSettingUser > 0) {
      wx.navigateTo({
        url: '/pages/myOrders/myOrders'
      })
    } else {
      this.setData({
        authSettingUser_task: false
      });
    }
  },

  // 打开各种状态的订单 页面
  showTheOrders: function(e) {
    if (app.globalData.authSettingUser > 0) {
      var ordertype = e.detail.order_type;
      console.log(ordertype)
      if (ordertype == '退换/售后') {
        wx.navigateTo({
          url: '/pages/myOrders/myOrders?ordertype=' + '退换售后'
        })
      } else {
        wx.navigateTo({
          url: '/pages/myOrders/myOrders?ordertype=' + ordertype
        })
      }
    } else {
      this.setData({
        authSettingUser_task: false
      });
    }

  },

  // 打开我的名片 页面
  showMyCarte: function() {
    var that = this
    if (app.globalData.authSettingUser > 0) {
      if (that.data.userInfo.type == 2) {
        wx.redirectTo({
          url: '/pages/myCarte/myCarte',
        })
      } else {
        // 该用户没有购买名片 跳转购买名片
        wx.showModal({
          title: '提示',
          content: '您还未购买系统',
          showCancel: true,
          confirmText: '去购买',
          success: function(res) {
            if (res.confirm) {
              wx.switchTab({
                url: '/pages/carteShow/carteShow',
              })
              console.log('用户点击确定');
            } else if (res.cancel) {
              console.log('用户点击取消');
            }

          },
        })
      }
    } else {
      that.setData({
        authSettingUser_task: false
      });
    }

    // console.log('没有购买名片 跳转购买名片:', that.data.CarteInfo)
    // let CarteInfo = that.data.CarteInfo
    // CarteInfo.img.src = CarteInfo.img.src.split('?x-oss-process=style/index_mp')[0];
    // CarteInfo.comLogo.src = CarteInfo.comLogo.src.split('?x-oss-process=style/goods_skeletonize')[0];
    // wx.navigateTo({
    //   url: '/pages/buyCarte/buyCarte?params=' + JSON.stringify(that.data.CarteInfo)
    // })

  },
  hehuoCustormer: function() {
    if (app.globalData.authSettingUser > 0) {
      wx.navigateTo({
        url: '/shopPages/Customerlist/Customerlist?flag=5',
      })
    } else {
      this.setData({
        authSettingUser_task: false
      });
    }
  },

  // 弹出邀请码填写
  showAddCode: function() {

    var that = this

    if (app.globalData.authSettingUser > 0) {
      that.setData({
        codeShow: true
      });
    } else {
      that.setData({
        authSettingUser_task: false
      });
    }
  },
  showAddTel: function() {
    var that = this
    if (app.globalData.authSettingUser > 0) {
      that.setData({
        telShow: true,
        tel_: '',
        codePlace: '获取验证码',
        code_: '',
      });
    } else {
      that.setData({
        authSettingUser_task: false
      });
    }

  },

  code_input: function(e) {
    var that = this;
    var code = e.detail.value;
    if (code != '') {
      that.setData({
        code_btn: '确定',
        code: code
      });
    }
  },

  tel_input: function(e) {
    var that = this;
    var tel = e.detail.value;
    if (tel != '') {
      that.setData({
        tel: tel
      });
    }
  },

  tel_input_: function(e) {
    var that = this;
    var tel = e.detail.value;
    if (tel != '') {
      that.setData({
        tel_: tel
      });
    }
  },

  // 确定邀请码
  sureCode: function() {
    const that = this
    var code = that.data.code;
    var tel = that.data.tel;
    if (!app.phoneReg(tel)) {
      wx.showToast({
        title: '输入正确的手机号',
        icon: 'none',
        duration: 1000
      })

      return false;
    }
    if (code == '') {
      that.setData({
        codeShow: false
      });
    } else {
      wx.showLoading({
        title: '加载中',
      })
      var url2 = '/invite_code/CardCode_v4';
      var params2 = {
        uid: app.globalData.userInfo.id,
        code: code,
        tel: tel,
        timestamp: new Date().getTime(),
      };
      params2.sign = app.getSign(params2)
      app.HttpPostSend(url2, params2, function(res) {
        wx.hideLoading();
        app.showTipMsg(res.msg);
        if (res.code > 0) {
          var str = 'userInfo.type';
          that.setData({
            [str]: 2,
            codeShow: false
          });
        }

      });
    }
  },

  close_code: function() {
    this.setData({
      codeShow: false
    });
  },
  //输入验证码
  inputgetCode: function(e) {
    this.setData({
      code_: e.detail.value
    });
  },
  //获取验证码
  getCode: function(e) {
    const that = this
    var tel = that.data.tel_
    var test = /^((13[0-9])|(14[0-9])|(15[0-9])|(17[0-9])|(18[0-9]))\d{8}$/.test(tel)
    if (!app.phoneReg(that.data.tel_) || test != true) {
      wx.showToast({
        title: '输入正确的手机号',
        icon: 'none',
        duration: 1000
      })
      return false;
    }
    var url = '/ali_msg_api/sendMsg';
    var params = {
      phone: that.data.tel_
    };
    app.HttpPostSend(url, params, function(res) {
      if (res.code != "1") {
        app.showTipMsg(res.data);
        that.data.codePlace = "重新发送";
      } else {
        var curCount = 60;
        that.setData({
          codePlace: curCount + "s"
        })
        that.data.setInter = setInterval(function() {
          if (curCount == 1) {
            clearInterval(that.data.setInter);
            that.setData({
              codePlace: "重新发送"
            })
          } else {
            curCount = Number(curCount) - 1;
            that.setData({
              codePlace: curCount + "s"
            })
          }
        }, 1000);
      }
    });
  },
  close_tel: function() {
    this.setData({
      telShow: false
    });
  },

  // 弹出公司绑定
  showAddCompany: function() {
    const that = this
    that.setData({
      companyShow: true
    });
  },

  // 确定公司绑定
  sureCompany: function() {
    const that = this
    that.setData({
      companyShow: false
    });
  },
  showAddPhone: function(e) {
    const that = this
    if (!app.phoneReg(that.data.tel_)) {
      wx.showToast({
        title: '输入正确的手机号',
        icon: 'none',
        duration: 1000
      })

      return false;
    }
    var url = "/user_api/phoneAuth_v4";
    var param = {
      uid: app.globalData.userInfo.id,
      phone: that.data.tel_,
      code: that.data.code_,
      timestamp: new Date().getTime(),
    };
    param.sign = app.getSign(param)
    app.HttpPostSend(url, param,
      function(result_data) {
        if (result_data.msg != "success") {
          app.showTipMsg(result_data.msg);
        } else {
          app.globalData.userInfo = {
            ...result_data.data
          }
          wx.setStorage({
            key: 'userInfo',
            data: JSON.stringify({
              ...result_data.data
            })
          })
          that.setData({
            telShow: false,
            userInfo: result_data.data
          })
          clearInterval(that.data.setInter);

        }
      })
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {
    clearInterval(this.data.setInter);
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {
    clearInterval(this.data.setInter);
  },
  // .监听页面滚动距离scrollTop
  onPageScroll: function(e) {
    this.setData({
      scollTop: e.scrollTop
    })
  },
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },
  showCustormer: function() {
    if (app.globalData.authSettingUser > 0) {
      wx.navigateTo({
        url: '/shopPages/Customerlist/Customerlist?flag=0',
      })
    } else {
      this.setData({
        authSettingUser_task: false
      });
    }
  },
  showBoss: function() {
    if (app.globalData.authSettingUser > 0) {
      wx.navigateTo({
        url: '/radarPages/boosradar/boosradar',
      })
    } else {
      this.setData({
        authSettingUser_task: false
      });
    }
  },
  showRenmai: function() {
    if (app.globalData.authSettingUser > 0) {
      wx.navigateTo({
        url: '/radarPages/renmairadar/renmairadar',
      })
    } else {
      this.setData({
        authSettingUser_task: false
      });
    }

  },
  showShop: function() {
    if (app.globalData.authSettingUser > 0) {
      wx.navigateTo({
        url: '/radarPages/shopradar/shopradar',
      })
    } else {
      this.setData({
        authSettingUser_task: false
      });
    }
  },
  showApply: function() {
    if (app.globalData.authSettingUser > 0) {
      wx.navigateTo({
        url: '/shopPages/enterprise/enterprise',
      })
    } else {
      this.setData({
        authSettingUser_task: false
      });
    }

  },
  showGenjin: function() {
    if (app.globalData.authSettingUser > 0) {
      wx.navigateTo({
        url: '/radarPages/mygenjin/mygenjin',
      })
    } else {
      this.setData({
        authSettingUser_task: false
      });
    }

  },
  showHehuo() {
    wx.navigateTo({
      url: '/shopPages/Partner/Partner',
    })
  },

  companyInvite: function() {
    var that = this;
    wx.request({
      // url: 'https://csboss.51jlkj.com/api/1.0/companyInvite',
      url: app.globalData.bossradar + '/api/1.0/companyInvite',
      data: {
        uid: app.globalData.userInfo.id,
      },
      method: 'POST',
      header: {
        'content-type': 'application/json' // 默认值
      },
      success(res) {
        // console.log("++++++++++++++++" + JSON.stringify(res.data.data));
        that.setData({
          bossId: res.data.data.bossId
        })
        that.setData({
          inviteId: res.data.data.id
        })
        that.setData({
          companyId: res.data.data.companyId
        })
        if (res.data.data.role == 1) {
          if (res.data.data.flag == 0) {
            wx.showModal({
              title: '提示',
              content: res.data.data.bossName + '邀请你加入' + res.data.data.companyName,
              success(res) {
                if (res.confirm) {
                  console.log('用户点击确定'),
                    that.saveStaffTwo();
                } else if (res.cancel) {
                  console.log('用户点击取消')
                  that.saveStaff(2);
                }
              }
            })
          }
        } else if (res.data.data.role == 2) {
          if (res.data.data.flag == 0) {
            wx.showModal({
              title: '提示',
              content: res.data.data.bossName + '邀请你成为' + res.data.data.companyName + '合伙人',
              success(res) {
                if (res.confirm) {
                  console.log('用户点击确定'),
                    that.saveStaffTwo1();
                } else if (res.cancel) {
                  console.log('用户点击取消')
                  that.saveStaff1(2);
                }
              }
            })
          }
        }
      }
    })
  },

  saveStaff: function(type) {
    console.log(this.data.bossId);
    var that = this;
    wx.request({
      url: app.globalData.bossradar + '/api/1.0/saveStaff',
      data: {
        uid: app.globalData.userInfo.id,
        bossId: that.data.bossId,
        companyId: that.data.companyId,
        type: type
      },
      method: 'POST',
      header: {
        'content-type': 'application/json' // 默认值
      },
      success(res) {
        console.log("++++++++++++++++" + JSON.stringify(res.data));
      }
    })
  },

  saveStaffTwo: function() {

    var that = this;
    wx.request({
      // url: 'http://192.168.0.107:8080/manager/saveStaffSuccess',
      url: baseUrl + '/manager/saveStaffSuccess',
      data: {
        uid: app.globalData.userInfo.id,
        id: that.data.inviteId,
        bossId: that.data.bossId,
        companyId: that.data.companyId,
        type: 1
      },
      method: 'POST',
      header: {
        'content-type': 'application/json' // 默认值
      },
      success(res) {
        var re_data = res.data;
        if (re_data.code > 0) {

          wx.showModal({
            title: '提示',
            content: re_data.msg,
            showCancel: false,
            success: function() {
              var str = 'userInfo.type';
              var mycompanyShow = 'userInfo.mycompanyShow';
              that.setData({
                [str]: 2,
                [mycompanyShow]: 0
              });

            }
          })
        } else {
          wx.showModal({
            title: '提示',
            content: re_data.msg,
            showCancel: false,
            success: function() {

            }
          })
        }
      }
    })
  },
  saveStaff1: function(type) {
    console.log(this.data.bossId);
    var that = this;
    wx.request({
      url: app.globalData.bossradar + '/api/1.0/savePartner',
      data: {
        uid: app.globalData.userInfo.id,
        bossId: that.data.bossId,
        companyId: that.data.companyId,
        type: type
      },
      method: 'POST',
      header: {
        'content-type': 'application/json' // 默认值
      },
      success(res) {
        console.log("++++++++++++++++" + JSON.stringify(res.data));
      }
    })
  },
  saveStaffTwo1: function() {

    var that = this;
    wx.request({
      // url: 'http://192.168.0.107:8080/manager/saveStaffSuccess',
      url: baseUrl + '/manager/savePartnerSuccess',
      data: {
        uid: app.globalData.userInfo.id,
        id: that.data.inviteId,
        bossId: that.data.bossId,
        companyId: that.data.companyId,
        type: 1
      },
      method: 'POST',
      header: {
        'content-type': 'application/json' // 默认值
      },
      success(res) {
        var re_data = res.data;
        if (re_data.code > 0) {

          wx.showModal({
            title: '提示',
            content: re_data.msg,
            showCancel: false,
            success: function() {
              var str = 'userInfo.type';
              var mycompanyShow = 'userInfo.mycompanyShow';
              that.setData({
                [str]: 2,
                [mycompanyShow]: 0,
                hehuoShow: 1
              });

            }
          })
        } else {
          wx.showModal({
            title: '提示',
            content: re_data.msg,
            showCancel: false,
            success: function() {

            }
          })
        }
      }
    })
  },
  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage: function() {

  // }
})